/// Log工具类：打印日志相关
class Log {
  /// 默认日志TAG
  static String APP_TAG = "YJ";

  /// 默认日志TAG
  static const String _TAG_DEF = "TAG";

  /// 是否打开输出日志，true：log输出
  static bool isOpenLogDef = true;

  /// 日志TAG
  static String TAG = _TAG_DEF;

  /// 运行在Release环境时，inProduction为true；
  /// 当App运行在Debug和Profile环境时，inProduction为false。
  static const bool inProduction = bool.fromEnvironment("dart.vm.product");

  ///
  /// 初始化log
  ///
  /// [isOpenLog] 是否打开日志
  /// [tag] tag标识
  static void init(
      {String appTag = "", String tag = _TAG_DEF, bool isOpenLog = false}) {
    APP_TAG = appTag;
    isOpenLogDef = isOpenLog;
    TAG = tag;
  }

  ///
  /// 打印INFO日志
  /// 🟩 💚
  /// [object] 打印object内容
  /// [tag] tag标识
  static void i(Object object, {String tag = _TAG_DEF}) {
    _printLog(tag, '[I]💚', object);
  }

  ///
  /// 打印警告日志
  /// 🟧 ⚠️
  /// [object] 打印object内容
  /// [tag] tag标识
  static void w(Object object, {String tag = _TAG_DEF}) {
    _printLog(tag, '[W]⚠️️', object);
  }

  ///
  /// 打印错误日志
  /// 🟥 ⛔
  /// [object] 打印object内容
  /// [tag] tag标识
  static void e(Object object, {String tag = _TAG_DEF}) {
    _printLog(tag, '[E]⛔', object);
  }

  ///
  /// 打印debug日志
  /// 🟦 💙
  /// [object] 打印object内容
  /// [tag] tag标识
  static void d(Object object, {String tag = _TAG_DEF}) {
    _printLog(tag, "[D]💙", object);
  }

  ///
  /// 输出日志
  ///
  /// [tag] tag标识
  /// [stag] stag标识，比如e、i、v等
  /// [object] 输出object内容
  static void _printLog(String tag, String stag, Object object) {
    if (!isOpenLogDef || inProduction) {
      return;
    }
    StringBuffer stringBuffer = StringBuffer();
    stringBuffer.write(APP_TAG + stag + " ");
    stringBuffer.write((tag.isEmpty) ? TAG : tag);
    stringBuffer.write(": ");
    stringBuffer.write(object);
    print(stringBuffer.toString());
    print('--------');
  }
}
